﻿using HKB.Common;
using HKB.Web.Admin;
using System;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Admin_ManageUploadFile : Admin, IRequiresSessionState
{
    public string FileName = "";
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(12))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        if (!base.IsPostBack)
        {
            this.TxtLastAccess.Text = DateTime.Now.ToShortDateString();
            this.TxtDir.Text = base.Server.MapPath("~/") + "\\AD\\UploadAdPic";
            if (!base.admin.CheckAdminPower(14))
            {
                this.Button3.Enabled = false;
            }
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(14))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "UploadFile");
            base.WriteRightErrMsg();
        }
        string text = "";
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)gridViewRow.FindControl("CheckBox1");
            if (checkBox.Checked)
            {
                text = text + gridViewRow.Cells[4].Text + ",";
            }
        }
        if (text.Length > 2)
        {
            text = text.Remove(text.Length - 1);
            FileIO.DelecteFiles(text);
            this.ObjectDataSource1.Update();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(14))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "Ads");
            base.WriteRightErrMsg();
        }
        if (this.GridView1.SelectedIndex > -1)
        {
            string text = this.GridView1.SelectedRow.Cells[4].Text;
            FileIO.DelecteFile(text);
            this.ObjectDataSource1.Update();
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        bool flag = base.admin.CheckAdminPower(14);
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            Image image = (Image)gridViewRow.FindControl("Image1");
            Panel panel = (Panel)gridViewRow.FindControl("Panel1");
            Label label = (Label)gridViewRow.FindControl("Label1");
            this.FileName = image.ImageUrl.ToString();
            if (this.FileName.Length >= 2)
            {
                this.FileName = this.FileName.Substring(2, this.FileName.Length - 2);
            }
            if (!File.Exists(base.Server.MapPath(".." + this.FileName)))
            {
                image.Visible = false;
                panel.Visible = false;
                label.Visible = true;
                label.Text = "文件已经被删除";
            }
            if (gridViewRow.Cells[5].Text != "swf")
            {
                image.Visible = true;
                panel.Visible = false;
                label.Visible = false;
            }
            else
            {
                if (gridViewRow.Cells[5].Text == "swf")
                {
                    image.Visible = false;
                    panel.Visible = true;
                    label.Visible = false;
                    image.AlternateText = "flash文件，点击查看";
                }
            }
            if (!flag)
            {
                ((LinkButton)gridViewRow.Cells[7].FindControl("cl")).Visible = false;
            }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
}
